﻿<Window x:Class="GUI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm ="clr-namespace:DemoRealtimeData.ViewModel;assembly=ViewModel"
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" 
        Title="Demo Realtime Datas" Height="611.5" Width="796"
        Loaded="Window_Loaded">
    <Window.Resources>
        <Thickness x:Key="margin"
                   Left="5"
                   Top="2"
                   Right="5"
                   Bottom="2"/>
        <Style TargetType="ComboBox">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
        </Style>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
        </Style>
        <Style TargetType="Label">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
            <Setter Property="FontWeight" Value="Black"/>
        </Style>
        <Style TargetType="ListBox">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
        </Style>
        <Style TargetType="DataGrid">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
        </Style>
        <Style TargetType="GridSplitter">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
        </Style>
        <vm:DataType2DescriptionConverter x:Key="dttype2str"/>
    </Window.Resources>
    <DockPanel>
        <GroupBox Header="Control" DockPanel.Dock="Left" MinWidth="250">
            <DockPanel >
                <DockPanel DockPanel.Dock="Top">
                    <Label DockPanel.Dock="Left">Data Types:</Label>
                    <ComboBox ItemsSource="{Binding Path=DataTypes}" 
                          DisplayMemberPath="Value"
                          SelectedValuePath="Key"
                          SelectedValue="{Binding Path=CurrentDataType}"></ComboBox>
                </DockPanel>
                <Label DockPanel.Dock="Top">Devices:</Label>
                <Button DockPanel.Dock="Top" Content="Start"
                    Command="{Binding Path=StartCalculateCmd}"/>
                <ListBox ItemsSource="{Binding Path=AllDevices}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding Path=IsSelected}" Content="{Binding Path=Name}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </DockPanel>
        </GroupBox>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="2*" />
            </Grid.RowDefinitions>
            <GroupBox Grid.Row="0" Header="Historian Curves" >
                <d3:ChartPlotter Name="plotter"  >
                    <d3:ChartPlotter.HorizontalAxis>
                        <d3:HorizontalDateTimeAxis Name="dateAxis"/>
                    </d3:ChartPlotter.HorizontalAxis>
                    <d3:Header >
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=CurrentDataType,Converter={StaticResource dttype2str}}"/>
                            <TextBlock Text=" Curves"/>
                        </StackPanel>
                    </d3:Header>
                    <d3:VerticalAxisTitle Content="Value"/>
                    <d3:HorizontalAxisTitle Content="Time"/>

                </d3:ChartPlotter>
            </GroupBox>
            <GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
            <GroupBox Grid.Row="2" Header="Current Values">
                <DataGrid  AutoGenerateColumns="False" ItemsSource="{Binding Path=DisplayMeasurements}">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Time" Binding="{Binding Path=Time, StringFormat='HH:mm:ss'}" IsReadOnly="True"/>
                        <DataGridTextColumn Header="Device" Binding="{Binding Path=Device}" IsReadOnly="True"/>
                        <DataGridTextColumn Header="Type" Binding="{Binding Path=DataType, Converter={StaticResource dttype2str}}" IsReadOnly="True"/>
                        <DataGridTextColumn Header="Value" Binding="{Binding Path=Value,StringFormat='{}{0:0.##}'}" IsReadOnly="True"/>
                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>
        </Grid>
    </DockPanel>
</Window>
